<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link href="../CSS/Search.css" rel="stylesheet" type="text/css"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Trần Quang Kha</title>
    </head>
    <body>
        <div id="Pages">
            <div id="User">
                <div class="login">
                    <input type="submit" name="Submit" value="Register">
                    <input type="submit" name="Submit" value="Login">
                    <a>Remember me</a><input type="checkbox" name="vehicle" value="Bike">
                    <input type="password" name="passwords" value=""><a>Password:</a>
                    <input type="text" name="Username" value=""><a>Username:</a>

                    <?php
                    require_once '../model/db.php';
                    require_once '../model/keywords.php';
                    require_once '../model/works.php';
                    require_once '../Class/Pagination.php';
                    ?>

                </div>
            </div>
            <div id="Banner">
                <img src="../Image/Banner.jpg">
            </div>
            <!-- Menu -->
            <div id="Menu">
                <ul>
                    <li><a href="#"><b>HOME</b></a></li>
                    <li><a href="#"><b>FORUMS</b></a></li>
                    <li><a href="#"><b>CONTENT</b></a></li>
                    <li><a href="#"><b>CONTACT</b></a></li>
                </ul>
                <div id="Search">
                    <input type="text" name="search" value="">
                    <input type="submit" name="Submit" value="Search">
                </div>
            </div>
            <!--End Menu -->
            <div id="content">
                <div id="edit">
                    <form method="post"      enctype="multipart/form-data">
                        <label for="file">Filename:</label>
                        <input type="file" name="file" id="file"><br>
                        <input type="submit" name="submit" value="Submit">
                    </form>


                    <?php
                    if (isset($_POST['submit'])) {
                        $file_name = '';
                        /////////////////////upload file
                        $allowedExts = array("gif", "jpeg", "jpg", "png");
                        $temp = explode(".", $_FILES["file"]["name"]);
                        $extension = end($temp);
                        if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png"))
                                //&& ($_FILES["file"]["size"] < 20000)
                                && in_array($extension, $allowedExts)) {
                            if ($_FILES["file"]["error"] > 0) {
                                echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
                            } else {
                                $file_name = $temp[0] . '--' . time() . '.' . $temp[1];
                                move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $file_name);
                                echo "Stored in: " . "images/" . $file_name;
                                $url = "images/" . $file_name;
                                echo "<img src='$url' width='40 px' /><br/>";
                            }
                        }
                        /////////////////////
                        $work = new work();
                        $data = array(
                            'id'    => @$_GET['edits']?$_GET['edits']:1,
                            'image' => $file_name
                        );
                        $work->update($data);
                    }
                    ?>
                </div>
                <div id="noidung">

                    <?php
                    $keywords = new work();
                    $page = 1;
                    $link = "search.php";
                    $per_page = PER_PAGE;
                    $from = $per_page * ($page - 1);
                    $to = PER_PAGE;
                    if (isset($_GET['page']))
                    $page = $_GET['page'];
                    $query = "SELECT * FROM works LIMIT $from ,$to";
                    $list = $keywords->works1();
                    $total = mysql_num_rows(mysql_query("SELECT * FROM works ")); //đếm số dòng
                    $list = $keywords->select($query);
                    var_dump($query);
                    ?>
                    <form method="GET">
                        <table border="1px">
                            <tr>
                                <td>ID</td>
                                <td>Name</td>
                                <td>Images</td>
                                <td>Khu Vực </td>
                                <td>Image</td>
                                <td>Options</td>
                            </tr>
                            <?php foreach ($list as $lists) : ?> 
                                <tr>
                                    <td><a><?php echo $lists['id']; ?></a></td>           
                                    <td><a href='<?php echo $lists['url']; ?>'><?php echo $lists['name']; ?></a></td>
                                    <td></td>
                                    <td><a><?php echo $lists['location']; ?></a></td>
                                    <td><a><img src="<?php echo $lists['image'];?>"></a></td>
                                    <td>
                                        <a href="edits.php?edits=<?php echo $lists['id']?>">Edit</a>
                                    </td>  
                                </tr>
                            <?php endforeach; ?>
                        </table>
                        <?php
                        if (!isset($_GET['page'])) {
                            for ($i = 1; $i <= 10; $i++) {
                                ?>
                                <a href='search.php?page=<?php echo $i ?>'><?php echo $i ?></a>
                            <?php } ?>
                            <a href='search.php?page=2'> [Trang sau] </a>
                            <?php if (isset($_GET['page'])) { ?>
                                <a href='search.php?page=<?php echo $_GET['page'] + 1 ?>'> Next </a>
                                <?php
                            }
                        } else {
                            $pagi = new Pagination();
                            $show = $pagi->paging($total, $per_page, $link);
                        }
                        ?>
                    </form>
                </div>
            </div>

        </div>
        <div id="Footer"></div>
    </body>
</html>
<?php



